package com.example.fpe_vote.db1.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.fpe_vote.db1.entity.NomineeInfo;
import com.example.fpe_vote.db1.mapper.NomineeInfoMapper;
import com.example.fpe_vote.db1.service.INomineeInfoService;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2022-12-01
 */
@Service
public class NomineeInfoServiceImpl extends ServiceImpl<NomineeInfoMapper, NomineeInfo> implements INomineeInfoService {

    @Override
    public void addVotes(String[] voteNomineeIds) {
        for(String id:voteNomineeIds){
            NomineeInfo nomineeInfo=getById(Integer.parseInt(id));
            nomineeInfo.setVotes(nomineeInfo.getVotes()+1);
            saveOrUpdate(nomineeInfo);
        }
    }

    @Override
    public Integer getNomineeNums(String prizeNum) {
        QueryWrapper<NomineeInfo> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("prize_num",prizeNum);
        return list(queryWrapper).size();
    }

    @Override
    public NomineeInfo queryByInfo(String userName, String zwName, String prizeNum) {
        QueryWrapper<NomineeInfo> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("prize_num",prizeNum);
        queryWrapper.eq("zwname",zwName);
        queryWrapper.eq("name",userName);
        return getOne(queryWrapper);
    }

}
